// https://leetcode.cn/problems/single-number-ii/description/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int a = 0, b = 0;

        for (int num : nums) {
            b = ~a & (b ^ num);
            a = ~b & (a ^ num);
        }
        return b;
    }
};